﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using NTTHAO.Web.BL.CommonSite;
using System.Net.Mail;
using NTTHAO.CommonWeb;
using NTTHAO.Sites.CommonSite;
using NTTHAO.Web.BL.Authentication;

//using NTTHAO.Sites.CanNhaMoUoc;

public partial class Sites_CanNhaMoUoc_Webparts_User_UserEdit : NTTHAO.CommonWeb.CommonUserControl
{
    public string _Message = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Authentication.RequireAuthentication())
        {
            return;
        }
        aspnetForm.Action = Request.RawUrl;
        if (!IsPostBack)
        {
            try
            {
                User user = new User(Authentication.Name);
                txtAddress.Value = user.Address;
                txtContactName.Value = user.FullName;
                txtHomePhone.Value = user.TelePhone;
                txtPhone.Value = user.MobilePhone;
                rdbNational_0.Checked = ("Việt Nam".Equals(user.Nationality, StringComparison.OrdinalIgnoreCase));
                rdbNational_1.Checked = !rdbNational_0.Checked;
                cmbUserTitle.Text = user.UserTitle.ToString();
            }
            catch
            {
                Response.Redirect("/");
                return;
            }
        }
    }

    public void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            User user = new User(Authentication.Name);
            user.Address = txtAddress.Value;
            user.FullName = txtContactName.Value.Trim();
            user.TelePhone = txtHomePhone.Value;
            user.MobilePhone = txtPhone.Value;
            user.Nationality = rdbNational_1.Checked ? "Nước ngoài" : "Việt Nam";
            user.UserTitle = Convert.ToInt32(cmbUserTitle.SelectedValue);
            user.Update();

            _Message = "Thông tin của bạn đã được cập nhập.";
        }
        catch
        {
            Response.Redirect("/");
            return;
        }
    }
}
